package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 三石
 * Date: 2022-05-21
 * Time: 18:34
 */
public class AddOperation implements IOoperation{

    @Override
    public void work(BookList bookList) {
        System.out.println("新增图书！");
        Scanner scanner=new Scanner(System.in);

        System.out.println("请输入图书的名字：");
        String name= scanner.nextLine();

        System.out.println("请输入作者：");
        String author=scanner.nextLine();

        System.out.println("请输入书籍类型：");
        String type= scanner.nextLine();

        System.out.println("请输入书籍价格：");
        double price= scanner.nextDouble();

        //新建立一本图书，并放入对应元素
        Book book=new Book(name,author,price,type);

        //获取书架最后一本书的位置
        int crrentSize=bookList.getUsedSize();

        //把新增的书放入对应位置（最后一本书的后面）
        bookList.setBooks(crrentSize,book);

        //此时书架个数+1
        bookList.setUsedSize(crrentSize+1);

        System.out.println("新增图书成功！");
    }
}
